<template>
  <CoordinationDetail ref="coordinationDetail" @update="updateList" />
  <DelayDetail ref="delayDetail" @update="updateList" />
  <CoordinationAdd ref="coordinationAdd" @update="updateList" />
  <DelayAdd ref="delayAdd" @update="updateList" />
  <TaskApprovalDialog ref="taskApprovalDialog" @update="updateList" />
  <ReceiveMatterDialog ref="receiveMatterDialog" @update="updateList" />
  <ProcessDialog ref="processDialog" @update="updateList" />
  <ReviewDialog ref="reviewDialog" @update="updateList" />
  <FollowDialog ref="followDialog" />
</template>

<script lang="ts" setup>
import CoordinationDetail from '@/views/application/coordination/CoordinationDetail.vue'
import { ETaskType } from '@/views/events/mine/util'
import { useTemplateRef } from 'vue'
import DelayDetail from '@/views/application/delay/DelayDetail.vue'
import { EDetailType } from '@/views/application/typings'
import ReceiveMatterDialog from '@/views/mission/receiveMatter/ReceiveMatterDialog.vue'
import ProcessDialog from '@/views/mission/process/ProcessDialog.vue'
import ReviewDialog from '@/views/mission/reviewTask/ReviewDialog.vue'
import TaskApprovalDialog from '@/views/mission/taskApproval/TaskApprovalDialog.vue'
import FollowDialog from '@/views/mission/follow/FollowDialog.vue'
import CoordinationAdd from '@/views/application/coordination/CoordinationAdd.vue'
import DelayAdd from '@/views/application/delay/DelayAdd.vue'
import { EApproveStatus } from '../statusShow/util'

const emits = defineEmits(['update'])

const followDialog =
  useTemplateRef<InstanceType<typeof FollowDialog>>('followDialog')

const delayDetail =
  useTemplateRef<InstanceType<typeof DelayDetail>>('delayDetail')

const coordinationDetail =
  useTemplateRef<InstanceType<typeof CoordinationDetail>>('coordinationDetail')

const receiveMatterDialog = useTemplateRef<
  InstanceType<typeof ReceiveMatterDialog>
>('receiveMatterDialog')

const processDialog =
  useTemplateRef<InstanceType<typeof ProcessDialog>>('processDialog')

const reviewDialog =
  useTemplateRef<InstanceType<typeof ReviewDialog>>('reviewDialog')

const taskApprovalDialog =
  useTemplateRef<InstanceType<typeof TaskApprovalDialog>>('taskApprovalDialog')

const coordinationAdd =
  useTemplateRef<InstanceType<typeof CoordinationAdd>>('coordinationAdd')
const delayAdd = useTemplateRef<InstanceType<typeof DelayAdd>>('delayAdd')

function show(
  type: ETaskType,
  task: Record<string, any>,
  approve = EDetailType.VIEW,
) {
  switch (type) {
    case ETaskType.协调审核:
      task.applyStatus === EApproveStatus['不通过']
        ? coordinationAdd?.value?.show(task.matterId, task.id)
        : coordinationDetail?.value?.show(task.id, approve)
      break
    case ETaskType.延期审核:
      task.applyStatus === EApproveStatus['不通过']
        ? delayAdd?.value?.show(task.matterId, task.id)
        : delayDetail?.value?.show(task.id, approve)
      break
    case ETaskType.任务审批:
      taskApprovalDialog?.value?.show(task, approve)
      break
    case ETaskType.事项签收:
      receiveMatterDialog?.value?.show(task, approve)
      break
    case ETaskType.事项办理:
      processDialog?.value?.show(task)
      break
    case ETaskType.办理审核:
      reviewDialog?.value?.show(task, approve)
      break
    case ETaskType.事项详情:
      followDialog?.value?.show(task)
      break
    default:
      break
  }
}

function updateList() {
  emits('update')
}
defineExpose({
  show,
})
</script>
